<template>
  <view class="password">
    <view class="pas-header">
      <img src="/static/other/changePassword/left_arrow.png" alt="返回" mode="aspectFill" class="pas-header-img"
        @click="goback()" />
      <text class="pas-header-text">修改密码</text>
      <text class="null"></text>
    </view>
    <view class="pas-form">
      <view class="pas-form-text">
        <text class="sign">*</text>
        <text class="text">忘记密码请和管理人员沟通</text>
      </view>
      <view class="pas-form-item">
        <label class="pas-form-item-label">旧密码</label>
        <u-input type="password" v-model="oldPassword" placeholder="请输入旧密码" class="pas-form-item-input"
          required="true"></u-input>
      </view>
      <view class="pas-form-text">
        <text class="sign">*</text>
        <text class="text">密码必须由数字、大小写字母、特殊字符组合，请输入12~16位</text>
      </view>
      <view class="pas-form-item">
        <label class="pas-form-item-label">新密码</label>
        <u-input type="password" v-model="newPassword" placeholder="请输入新密码" class="pas-form-item-input"></u-input>
      </view>
      <view class="pas-form-item">
        <label class="pas-form-item-label">再次输入</label>
        <u-input type="password" v-model="confirmPassword" placeholder="请再次输入新密码" class="pas-form-item-input"></u-input>
      </view>
      <view class="pas-form-confirm">
        <view class="pas-form-item">
          <label class="pas-form-item-label">验证码</label>
          <u-input type="password" v-model="securityCode" placeholder="验证码" class="pas-form-item-input"></u-input>
        </view>
        <text class="filler"></text>
        <img src="/static/other/changePassword/yzm.jpg" alt="验证码" mode="aspectFill" class="pas-form-confirm-img" />
      </view>
      <u-button class="pas-form-btn" text="确 定" @click="submit()"></u-button>
    </view>
    <view class="pas-bottom"></view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        oldPassword: '',
        newPassword: '',
        confirmPassword: '',
        securityCode: '',
        loginInfo:{}
      }
    },
    OnLoad(){
      this.loginInfo=uni.getStorageSync('loginInfo');
    },
    methods: {
      goback() {
        uni.navigateBack({
          delta: 1
        });
      },
      submit() {
        if (!this.oldPassword || !this.newPassword || !this.confirmPassword || !this.securityCode)        {
          uni.showToast({
            title: '请填写完整信息',
            icon: 'none'
          });
          return;
        }
        else if (this.newPassword !== this.confirmPassword) {
          uni.showToast({
            title: '两次输入的新密码不一致',
            icon: 'none'
          });
          return;
        }
        else if (this.newPassword.length < '12' || this.newPassword.length > '16') {
          uni.showToast({
            title: '字数错误请重新输入',
            icon: 'none'
          });
          return;
        }
        else{
          uni.setStorageSync('loginInfo', {
            password: this.newPassword
          });
          uni.showToast({
            title: '密码修改成功,请退出重新登录',
            icon: 'none'
          });
          setTimeout(()=>{
           uni.redirectTo({
             url: '/pages/login/login'
           });
          },1000)
        }
      }
    },
  }
</script>

<style lang="scss" scoped>
  .password {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(to bottom, #eaf6ff, #f5faff);

    .pas-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background-color: rgb(31, 81, 154);
      padding: 30px 20px 13px 20px;

      .pas-header-img {
        width: 10px;
        height: 15px;
      }

      .pas-header-text {
        font-size: 17px;
        font-weight: 600;
        color: white;
      }

      .null {
        width: 10px;
        height: 15px;
      }
    }

    .pas-form {
      flex: 1;
      padding: 15px;
      display: flex;
      flex-direction: column;

      .pas-form-text {
        display: flex;
        align-items: center;
        margin-bottom: 10px;

        .sign {
          font-size: 17px;
          color: rgb(213, 41, 84);
        }

        .text {
          font-size: 10px;
          font-weight: 300;
          color: gray;
        }
      }

      .pas-form-item {
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        background-color: white;
        padding: 5px 15px;
        border-radius: 50px;

        .pas-form-item-label {
          width: 60px;
          font-size: 15px;
        }
      }

      .pas-form-confirm {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .pas-form-item-label {
          width: 60px;
          font-size: 15px;
        }

        .pas-form-confirm-img {
          margin: 0 20px;
          padding: 0 0 13px 0;
          width: 90px;
          height: 40px;
        }

        .filler {
          flex: 1;
        }
      }

      .pas-form-btn {
        margin-top: 10px;
        height: 50px;
        color: white;
        background-color: rgb(2, 126, 250);
        border-radius: 50px;
      }
    }

    .pas-bottom {
      width: 100%;
      height: 20px;
      background: white;
    }
  }
</style>
